package lt.web.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lt.web.mapper.AppVersionMapper;
import lt.web.pojo.AppVersion;
import lt.web.service.AppVersionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AppVersionServiceImpl extends ServiceImpl<AppVersionMapper,AppVersion> implements AppVersionService {

    @Autowired
    AppVersionMapper appVersionMapper;

    @Override
    public List<AppVersion> getAppVersionByvId(Integer id) {
        return appVersionMapper.getAppVersionByvId(id);
    }

    @Override
    public List<AppVersion> getAppVersionList(Integer id) {
        return appVersionMapper.getAppVersionList(id);
    }

    @Override
    public Integer insertVersion(AppVersion appVersion) {
        int insert = appVersionMapper.insert(appVersion);
        return insert;
    }

    @Override
    public Integer selectNewVersionidByAppid(Integer appId) {
        AppVersion appid = appVersionMapper.selectNewVersionidByAppid(appId);
        if (appid.getId()!=null){
            Long id = appid.getId();
            Integer id2 = Integer.valueOf(String.valueOf(id));
            return id2;
        }
        return 0;
    }

    @Override
    public AppVersion selectNewVersion(Integer appinfoid) {
        return appVersionMapper.selectNewVersionidByAppid(appinfoid);
    }

    @Override
    public boolean updateNewVersion(AppVersion appVersion) {
        UpdateWrapper<AppVersion> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("id", appVersion.getId());
        // 执行更新操作
        int update = appVersionMapper.update(appVersion, updateWrapper);
        return update > 0;
    }
}
